//
//  TalkfunLive.h
//  CloudLive
//
//  Created by LuoLiuyou on 16/8/18.
//  Copyright © 2016年 Talkfun. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "TalkfunSDK.h"
#import "TalkfunSDKLifeLiveConfig.h"
#import "TalkfunCloudLiveSDK.h"
#import <AVFoundation/AVFoundation.h>
NS_ASSUME_NONNULL_BEGIN
@protocol TalkfunLiveDelegate <NSObject>

@optional


/**@name 房间事件回调
 * - 如果加入成功，code 会是一个正数（code = 0），代表加入房间成功）。
 * - 如果加入失败，code 会是一个负数（code < 0），代表进房失败的错误码。
 *  进房失败的错误码含义请参见[错误码  TalkfunLiveConfig 文件的TalkfunLiveError 枚举
 */
- (void)onEnterRoom:(NSInteger)code result:(TFError*)error;
/** @name 当前用户进入房间触发
     详见 TFMember.h 中的定义
*/
- (void)onMemberJoinMe:(TFMember*)result;
/** @name 其它人进入房间触发
     详见 TFMember.h 中的定义
*/
- (void)onMemberJoinOther:(TFMember*)result;
/** @name 有人退出房间
     详见 TFMember.h 中的定义
*/
- (void)onMemberLeave:(TFMember*)result;
/**
 @name 同时在线人数  (真实人+虚拟人员 的总数)
*/
- (void)onPeakConcurrentUsers:(NSInteger)total;
/** @name 更新了机器人成员列表*/
- (void)onCustomerServiceListUpdate:(NSMutableArray<TFMember *>* )robotList;
/**
 @name 已直播时长
*/
- (void)onLiveDuration:(TFLiveDuration*)result;
/**
 @name 商品列表的事件回调
       商品状态变更时会实时更新列表
       self.lifeConfig.store.goods 与当前goods 是同一个列表
*/
- (void)onGoodsUpdate:(NSMutableArray <TFgoods *>* )goodsList;
/*!
 *连接状态  VCSessionDelegate
 */
- (void)streamStatusChanged:(TalkfunLiveStreamState)sessionState;
/*!
 * 连接成功后是否成功上课
 */
- (void)liveStatusChanged:(TalkfunLiveState)liveState;
/**
    直播的延时
   <= 50 网络好
   >50     <=150 网络一般
    >150 网络差
 */
- (void)liveDelay:(NSString*)delay;
/**
 直播的丢包
 <10  网络好
 <20-30 网络一般
 其它   网络差

 */
- (void)livePacketLoss:(NSString*)percentage;
/**
     大班直播的音量分贝 (0 -1)
 */
- (void)onVoiceCounts:(CGFloat)volume;
/**
 获取谁发放hb数据
 */
-(void)onHBsend:(TalkfunHBModel *)model;
/**
    第三方通知定制回调
 */
- (void)onBroadcastThird:(TalkfunBroadcastThird*)result;
/** @name 接收别人的聊天事件回调
    详见 TFChatSend.h 中的定义
 */
- (void)onDidReceiveText:(TFChatData*)result;

/** @name 删除聊天事件回调
 */
- (void)onChatDel:(NSString*)uuid;
/** @name 接收别人发送的花朵
 */
- (void)onFlowerSend:(TFLiveFlowerData*)result;
/** @name 课程超时*/
- (void)onCourseExpire;
/** @name 直播结束
          (服务器自动下发的指令)
 */
- (void)onLiveStop;
/** @name 主播违规直播被踢*/
- (void)onZhuboKicked;
/**
 @name 接收别人的提问
*/
- (void)onQuestionAsk:(TFQuestionData*)result;
/**
 @name 接收助教回复的提问
*/
- (void)onQuestionReply:(TFQuestionData*)result;
/**
 @name 删除提问
*/
- (void)onQuestionDelete:(TFQuestionData*)result;
/**
 @name  监听机器人标签
*/
- (void)onUserTagShow:(TFuserTagShow*)result;
/**
 @name 课程冲突
*/
- (void)onCourseConflict:(TFcourseConflict*)result;
/**@name 直播过程中发生错误
 */
- (void)anErrorOccurred:(TFError*)error;
/**
 @name  监听别人的点赞
*/
- (void)onLikePut:(TFLikeData*)likeData;
@end

@interface TalkfunLive : NSObject
/*
 课程数据
 onEnterRoom:result:()回调后, roomInfo的值才准确
 */
@property (nonatomic,strong)TalkfunLiveRoomInfo *roomInfo;
/**配置课程类型*/
@property (nonatomic,assign) TalkfunCourseMode courseMode;
/**代理*/
@property (atomic, weak)   id<TalkfunLiveDelegate> delegate;
/**视频预览VIEW*/
@property(nonatomic, strong)  UIView *preview;
/**视频预览VIEW 的模式
      默认 TalkfunPreviewScalingModeFill 图像铺满屏幕，不留黑边，如果图像宽高比不同于屏幕宽高比，部分画面内容会被裁剪掉
 */
@property(nonatomic, assign)TalkfunPreviewScalingMode previewScalingMode;
/**水印*/
@property (nonatomic, strong, nullable) UIView *warterMarkView;
//该属性表示麦克风音量增益因子，初始化时默认为1.0，推流开始后可以修改，其取值范围为[0, 1]
@property (atomic, assign) float micGain;//0~1.0

//1~3; // 该属性表示对原始视频进行缩放的比例，初始化时默认为1，推流开始后可以修改，其取值范围为(1, 3]
@property (nonatomic, assign) CGFloat zoomScale;
//网络状态
@property (nonatomic,assign) TalkfunCloudLiveNetworkStatus networkStatus;
//设置美颜
@property (nonatomic,assign) BOOL beauty;
/**视频录制 开关   默认为开启录制
   self.saveLocalVideo是进入直播间后配置
   也与相关,TalkfunSetting 是未进入直播前配置
 [[TalkfunSetting shared]getSaveLocalVideo]
 [[TalkfunSetting shared]setSaveLocalVideo:sender.on];
 
//空间小于3 000 MB* 无法开启录制

 */
@property (nonatomic, assign) BOOL saveLocalVideo;

/**前置摄像头的远程预览为水平翻转  默认 false*/
@property (nonatomic, assign) BOOL mirror;
/**前置摄像头的本地预览锁定为水平翻转  默认 true */
@property (nonatomic, assign) BOOL frontCameraPreviewLockedToFlipHorizontally;
/// 视频输出方向
@property (nonatomic, assign) UIInterfaceOrientation outputImageOrientation;
/// 自动旋转(这里只支持 left 变 right  portrait 变 portraitUpsideDown)
@property (nonatomic, assign) BOOL autorotate;
/**单例*/
+ (TalkfunLive *)shareInstance;
/** 进入房间
 *  调用  enterRoom() 接口执行进房操作后，会收到来自 SDK 的 onEnterRoom:result:() 回调：
 * @param param 进房参数，请参考 TalkfunLiveInitParams
*/
- (void)enterRoom:(TalkfunLiveInitParams *)param;
/**
 *  销毁(退出控制器时调用)
 */
- (void)shutdown;
/*!
 *前后摄像头  NO :后       YES:前
 */
- (void)setCameraFront:(BOOL)bCameraFrontFlag;
/*!
 *设备授权相关的接口
 */
-(void)applyPermission:(void (^)(BOOL state))callback;
/**
 *  开始直播
 */
- (void)startLive:(void (^)(NSDictionary* data))callback;
/**
 *  结束直播
 */
- (void)stopLive:(void (^)(NSDictionary* result))callback;
/**
 *  开启摄像头
 */
- (void)cameraStart:(void (^)(NSDictionary* result))callback;
/**
 *  关闭摄像头
 */
- (void)cameraStop:(void (^)(NSDictionary* result))callback;
/**
 *  暂停直播
 */
- (void)pauseLive:(void (^)(NSDictionary* result))callback;
/**
 *  恢复直播
 */
- (void)resumeLive:(void (^)(NSDictionary* result))callback;
/**
 *  触发某个事件(没有回调)
 */
- (void)emit:(NSString *)event params:(id)params;
/**
 *  触发某个事件(有回调)
 */
- (void)emit:(NSString *)event params:(id)params callback:(void (^)(id result))callback;
/**
 *  监听事件
 */
- (void)on:(NSString *)event callback:(void (^)(id result))callback;
/** 获取分辨率列*/
- (NSArray*)getDefinitionList;
/**  设置分辨率*/
- (void)setDefinition:(NSDictionary*)config  callback:(void (^)(NSInteger code ,TFError *_Nullable  error))callback;
/** 获取可加速的列表*/
- (NSArray*)getSpeedLineList;
/**  设置加速线路*/
- (void)setSpeedup:(NSDictionary*)dict callback:(void (^)(id  obj))callback;
//直播时间是否超出课程时间
//onEnterRoom:result:()回调后, getLiveTimeout的值才准确
- (BOOL)getLiveTimeout;
//在线人员数据 2.0
- (void)getMemberList:(TFMemberParams *)params
             callback:(void (^__nullable)(NSInteger code ,NSMutableArray <TFMember *>*_Nullable  list ,TFError *_Nullable  error))callback;
//在线学生数据 2.0
- (void)getUserList:(TFMemberParams *)params
           callback:(void (^__nullable)(NSInteger code ,NSMutableArray <TFMember *>*_Nullable  list ,TFError *_Nullable  error))callback;
/* 设置商品上架 */
-(void)goodsEditor:(TalkfunLiveGoodsParams*)params callback:(void (^__nullable)(NSInteger code ,NSMutableArray <TFgoods *>*_Nullable  list ,TFError *_Nullable  error))callback;
/** 发放列表*/
-(void)getPacketList:(TalkfunHandoutParams *)params callback:(void (^)(NSInteger code,NSMutableArray<TalkfunHandoutModel *> * _Nullable list,TFError *_Nullable  error ))callback;
/**
  发送聊天 2.0
  result result = 0 成功），result != 0 时为错误码。
 */
- (void)sendChat:(NSString *_Nullable)msg callback:(void (^__nullable) (NSInteger code,  TFChatData*_Nullable  model ,TFError *_Nullable  error))callback;
/**
  回复提问
 */
- (void)questionReply:(TalkfunQuestionReplyParameter *_Nullable)model callback:(void (^__nullable) (NSInteger code,  TFQuestionData*_Nullable  model ,TFError *_Nullable  error))callback;
/**
 *  获取提问列表
 **/
- (void)getAListOfQuestions:(void (^__nullable) (NSInteger code,  NSMutableArray <TFQuestionData *>*_Nullable  list ,TFError *_Nullable  error))callback;
/**
 *  设置你要上的课程
 */
- (id)initWithCourseID:(NSString *)courseID  courseName:(NSString*)course_name   startTimeDetai:(NSString*)start_time_detai   endTimeDetail:(NSString*)_end_time_detail NS_DEPRECATED(2_0, 2_0, 2_0, 2_0, "该方法已过期,请使用enterRoom:") ;
/**
 *   踢出房间
 **/
- (void)memberKick:(NSString*)xid  callback:(void (^__nullable) (NSInteger code ,TFError *_Nullable  error))callback;
/**
 *   禁言
 **/
- (void)chatDisable:(NSString*)xid  callback:(void (^__nullable) (NSInteger code ,TFError *_Nullable  error))callback;
/**
 *   解除禁言
 **/
- (void)chatEnable:(NSString*)xid  callback:(void (^__nullable) (NSInteger code ,TFError *_Nullable  error))callback;
/**
 *  设置你要上的课程
 */
- (id)initWithCourseID:(NSString *)courseID callback:(void (^)(NSDictionary* data))callback  NS_DEPRECATED(2_0, 2_0, 2_0, 2_0,"该方法已过期,请使用enterRoom:");
/**
 *  设置你要上的课程
 */
- (id)initWithCourseID:(NSString *)courseID  NS_DEPRECATED(2_0, 2_0, 2_0, 2_0, "该方法已过期,请使用enterRoom:");
/**在线人员数据*/
- (void)getMemberList:(void (^)(NSArray* result))callback NS_DEPRECATED(2_0, 2_0, 2_0, 2_0, "该方法已过期,请使用getMemberList:callback:") ;
/**所有学员*/
- (void)allStudents:(void (^)(NSArray* result))callback NS_DEPRECATED(2_0, 2_0, 2_0, 2_0, "该方法已过期,请使用getUserList:callback:");


/**微信分享信息*/
-(void)setWXShare:(void (^__nullable) (NSInteger code,  TalkfunWXShareParams*_Nullable  model ,TFError *_Nullable  error))callback;

/**生成海报图片*/
-(void)setWXPoster:(void (^__nullable) (NSInteger code,  NSString*_Nullable  urlPoster ,TFError *_Nullable  error))callback;

/*!
 *手动,自动对焦切换 // 该属性表示自动对焦时摄像头的对焦焦点，初始化时默认值为视频中心，推流开始后可以修改
    默认isManualFocus  == true
 */
@property (nonatomic, assign) BOOL isManualFocus;
/**设置焦点中心*/
- (void)setFocusBoxPoint:(CGPoint)point;

/** 相机是否可用
 AVCaptureDeviceTypeBuiltInUltraWideCamera  超广角摄像头  (近距离)
 AVCaptureDeviceTypeBuiltInWideAngleCamera 中距离 (这是大多数摄影和视频应用中使用的默认摄像头)
 AVCaptureDeviceTypeBuiltInTelephotoCamera  长焦摄像头（远摄摄像头）
 
 position:
    AVCaptureDevicePositionBack后摄像头
    AVCaptureDevicePositionFront前摄像头
 **/
- (BOOL)cameraAvailable:(AVCaptureDeviceType)cameraType position:(AVCaptureDevicePosition)position;

/***
    设置指定相机
 position:
    AVCaptureDevicePositionBack后摄像头
    AVCaptureDevicePositionFront前摄像头
 
 cameraToType:
 AVCaptureDeviceTypeBuiltInUltraWideCamera  超广角摄像头  (近距离)
 AVCaptureDeviceTypeBuiltInWideAngleCamera 中距离 (这是大多数摄影和视频应用中使用的默认摄像头)
 AVCaptureDeviceTypeBuiltInTelephotoCamera  长焦摄像头（远摄摄像头）
 

 ***/
- (BOOL)cameraToType:(AVCaptureDeviceType)cameraType position:(AVCaptureDevicePosition)position;
/**
 *  重新加载SDK  刷新
 **/
- (void)reload;
@end
NS_ASSUME_NONNULL_END

